package com.privated.work.exception;

import com.privated.work.common.Result;
import com.privated.work.utils.ResultUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.text.MessageFormat;

/**
 * 异常拦截
 * @author Leon
 * 2018年5月24日 下午4:06:36
 */
@RestControllerAdvice
public class GlobalExceptionHandler {



	/**
	 * 业务异常的时候用到
	 * @param e
	 * @return
	 */
	@ExceptionHandler(value = {BusinessException.class})
	public Result handleBusinessException(BusinessException e){
		e.setMsg(MessageFormat.format(e.getMsg(),e.getArguments()));
		return ResultUtils.error(Integer.parseInt(e.getCode()) , e.getMsg());
	}

}
